<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改任务')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
    <script type="text/javascript" th:src="@{/js/mission.js}"></script>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mission-edit" th:object="${sysMission}">
            <input name="missionId" th:field="*{missionId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">巡检任务名：</label>
                <div class="col-sm-8">
                    <input name="missionName" th:field="*{missionName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">巡检人员：</label>
                <div class="col-sm-8">
                    <select id="users" name="userIds" class="form-control select2-multiple" multiple required>
                        <option th:each="user:${userList}" th:id="|userId${user.userId}|" th:value="${user.userId}" th:text="${user.userName}" th:disabled="${user.status == '1'}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">巡检设备：</label>
                <div class="col-sm-8">
                    <select id="plants" name="plantIds" class="form-control select2-multiple" multiple required>
                        <option th:each="plant:${plantList}" th:id="|plantId${plant.id}|" th:value="${plant.id}" th:text="${plant.plantName}" th:disabled="${plant.plantStatus == '3'}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">巡检周期：</label>
<!--                <div class="col-sm-8">-->
<!--                    <input name="missionCycle" th:field="*{missionCycle}" class="form-control" type="text" required>-->
<!--                </div>-->
                <div class="col-sm-8">
                    <select name="missionCycle" th:with="type=${@dict.getType('sys_mission_cycle')}" onchange="changeView()" id="missionCycle" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="${sysMission.missionCycle}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="missionDate">
                <label class="col-sm-3 control-label is-required">巡检日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="missionDate" th:value="${#dates.format(sysMission.missionDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group" id="missionStartTime">
                <label class="col-sm-3 control-label is-required">开始时刻：</label>
                <div class="col-sm-8">
                    <input name="missionStartTime" th:field="*{missionStartTime}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group" id="missionEndTime">
                <label class="col-sm-3 control-label is-required">结束时刻：</label>
                <div class="col-sm-8">
                    <input name="missionEndTime" th:field="*{missionEndTime}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group" id="missionWeekday">
                <label class="col-sm-3 control-label is-required">每周几：</label>
<!--                <div class="col-sm-8">-->
<!--                    <input name="missionWeekday" th:field="*{missionWeekday}" class="form-control" type="text">-->
<!--                </div>-->
                <div class="col-sm-8">
                    <select name="missionWeekday" th:with="type=${@dict.getType('sys_weekday')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${sysMission.missionWeekday==dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="missionMonthday">
                <label class="col-sm-3 control-label is-required">每月几号：</label>
                <div class="col-sm-8">
<!--                    <input name="missionMonthday" th:field="*{missionMonthday}" class="form-control" type="text">-->
                    <select name="missionMonthday" th:with="type=${@dict.getType('sys_monthday')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${sysMission.missionMonthday==dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">任务状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_mission_status')}">
                        <input type="radio" th:id="${'missionStatus_' + dict.dictCode}" name="missionStatus" th:value="${dict.dictValue}" th:field="*{missionStatus}" required>
                        <label th:for="${'missionStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/mission";
        $("#form-mission-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-mission-edit').serialize());
            }
        }

        $("input[name='missionDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        changeView();

        let userIds = [[${userIds}]];
        userIds.forEach((item,index)=>{
            $("#userId"+item).prop("selected","selected");
        });
        let plantIds = [[${plantIds}]];
        plantIds.forEach((item,index)=>{
            $("#plantId"+item).prop("selected","selected");
        });
    </script>
</body>
</html>